package com.yufei.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yufei.dao.OrderDao;

import com.yufei.domain.Order;
import com.yufei.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
// 允许跨域
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderDao orderDao;

    //查询所有
    @GetMapping("/order")
    public List<Order> getAll() {
        return orderDao.selectList(null);
    }

    // 分页查询
    @GetMapping("/order/{current}")
    public IPage<Order> pageSelect2(@PathVariable Integer current) {
        IPage page = new Page(current, 12);
        orderDao.selectPage(page, null);
        return page;
    }

    //新增订单
    @PostMapping("/addorder")
    public String save(@RequestBody Order order) {
        orderDao.insert(order);
        return "OK";
    }

    //修改
    @PostMapping("/update2")
    public String update(@RequestBody Order order) {
        orderDao.updateById(order);
        return "OK";
    }

    //删除接口
    @PostMapping("/delete3/{id}")
    public int delete2(@PathVariable Integer id) {
        return orderDao.deleteById(id);
    }

    // 条件查询
    @GetMapping("/selectName3/{name}")
    public List selectName2(@PathVariable String name) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.like("name", name);
        return orderDao.selectList(qw);
    }


}
